<template>
  <fieldset>
    <legend>商品列表</legend>
    <ul>
      <li v-for="item in list" :key="item._id" @click="jump(item)">
        {{ item.productName }}
      </li>
    </ul>
  </fieldset>
</template>
<script>
export default {
  data() {
    return {
      list: [],
    };
  },
  mounted() {
    fetch("http://chst.vip:1234/api/getmoneyctrl")
      .then((body) => body.json())
      .then((res) => {
        console.log(res);
        this.list = res.result;
        // this.code = res.result.productId;
      });
  },
  methods: {
    jump(item) {
      this.$router.push({ path: `/detail/${item.productId}` });
      //通过索引
      // this.$router.push({ path: `/detail/${this.list[i].productId}` });
      // console.log(this.list);
    },
  },
};
</script>
